package henu.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

import henu.bean.Schedule;
import henu.bean.Teacher;
import henu.factory.DaoFactory;

public class ScheduleAction extends ActionSupport {
	HttpServletRequest request = ServletActionContext.getRequest();
	public String add(){
		String num = request.getParameter("num");
		String name = request.getParameter("name");
		String year = request.getParameter("year");
		String term = request.getParameter("term");
		String grade = request.getParameter("grade");
		Schedule sche = new Schedule();
		sche.setfCourseName(name);
		sche.setfCourseNum(num);
		sche.setfCourseYear(year);
		sche.setfCourseTerm(term);
		sche.setfGrade(grade);
		int n = 0;
		n = DaoFactory.createScheduleDao().add(sche);
		if(n == 1){
			return "add";
		}else{
			return ERROR;
		}
	}
	
	public String getAll(){
		String type = request.getParameter("type");
		List<Schedule> schelist = null;
		List<Teacher> teachers = null;
		teachers = DaoFactory.createTeacherDao().getAll();
		schelist = DaoFactory.createScheduleDao().getAll();
		request.getSession().setAttribute("teachers", teachers);
		request.getSession().setAttribute("schelist", schelist);
		if(type.equals("tea")){
			return "getAll";
		}else{
			return "stu_getAll";
		}
		
	}
}
